﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using GtsServer.Manage.Controller;
using GtsServer.Model;
using GtsServer.Common;

namespace GtsServer.Manage.IISPage.Ajax
{
    /// <summary>
    /// FeedBackAjax 的摘要说明
    /// </summary>
    public class FeedBackAjax : IHttpHandler
    {
        FeedBackController controller = new FeedBackController();
        public void ProcessRequest(HttpContext context)
        {
            string type = string.Empty;
            if (context.Request["action"] != null)
            {
                type = context.Request["action"];

                switch (type)
                {
                    case "GetList":
                        GetList(context);
                        break;
                    default:
                        break;
                }
            }
        }

        private void GetList(HttpContext context)
        {
            int pageIndex = Convert.ToInt32(context.Request["pageIndex"]);
            int pageSize = Convert.ToInt32(context.Request["pageSize"]);

            string imsi = context.Request["imsi"];
            string userAccount = context.Request["userAccount"];
            string start =  context.Request["startTime"];
            string end = context.Request["endTime"];

            int count = 0;
            List<FeedBack> list = controller.GetList(imsi,userAccount,start,end,pageIndex, pageSize, out count);

            for (int i = 0; i < list.Count; i++)
            {
                list[i].ContactWay = Microsoft.JScript.GlobalObject.encodeURIComponent(list[i].ContactWay);
                list[i].FeedBackContent = Microsoft.JScript.GlobalObject.encodeURIComponent(list[i].FeedBackContent);
            }

            context.Response.Write(JsonHelper.ListToJson<FeedBack>(list, count.ToString()));
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}